/**
 * 错误类型基类 <br>
 * 规范 {@link cause} 类型和构造
 *
 * @author 冰凝
 * @date 2023-02-22 02:24
 */
export class Throwable extends Error {
    public override message: string
    public override cause?: Throwable
    public causeError?: Error

    public constructor(message: string, cause?: Throwable | Error) {
        super(message)
        this.message = message

        if (cause) {
            if (cause instanceof Throwable) {
                this.cause = cause
            } else {
                this.causeError = cause
            }
        }
    }

    /**
     * 本地化消息 默认实现等同于 {@link message} <br>
     * 可作为错误消息本地化入口
     */
    public getLocalMessage(): string {
        return this.message
    }

    public override toString(): string {
        return super.toString()
    }
}

/**
 * <h2 style="color: red">严重系统错误</h2>
 * 一般导致业务中断. 应该全局处理
 */
export class SysError extends Throwable {}

/**
 * <h3>网络错误</h3>
 * 一般指 HTTP 状态错误
 */
export class NetworkError extends SysError {}
